package com.kotlinvben.service

import com.kotlinvben.entity.User
import org.springframework.cache.annotation.CacheEvict
import org.springframework.cache.annotation.Cacheable
import org.springframework.context.annotation.Lazy
import org.springframework.stereotype.Service

@Service
class UserCacheService(
   @Lazy private val userService: UserService
) {

    @Cacheable(value = ["users"], key = "#userId", unless = "#result == null")
    fun getUserById(userId: Long): User? {
        return userService.getUserById(userId)
    }

    @CacheEvict(value = ["users"], key = "#userId")
    fun deleteUserById(userId: Long) {
        log.info("deleting user cache: $userId")
    }

    companion object {
        private val log = org.slf4j.LoggerFactory.getLogger(UserCacheService::class.java)
    }

} 